from langchain_community.embeddings import DashScopeEmbeddings
#from langchain.vectorstores import  Milvus
from langchain_milvus import Milvus
from langchain_core.documents import  Document
from uuid import uuid4

#初始化模型
embeddings = DashScopeEmbeddings(
    model="text-embedding-v2",
    max_retries=3,
    dashscope_api_key="sk-4f1498f1c0314ba79ea2919bd7a02c4d"
)
vector_store = Milvus(
    embeddings,
    connection_args={"uri":"http://49.234.21.142:19530"},
    collection_name = "langchain_example",
)
document_1=Document(
    page_content="I hard chocolate chip pancakes and scrambled eggs for breakfast this morning.",
    metadata={"source":"tweet"},
)
document_2=Document(
    page_content="The weater forecast for tomorrow is cloudy and overcast,with a hight of 62 degress.",
    metadata={"source":"news"},
)
document_3=Document(
    page_content="Building an exciting new project with LangChain - come check it out!",
    metadata={"source":"tweet"},
)
document_4=Document(
    page_content="Robbers broke into the city bank and stole $1 million in cash.",
    metadata={"source":"news"},
)
document_5=Document(
    page_content="Wow! That was an amazing movie. I can not wait to see it again.",
    metadata={"source":"tweet"},
)
document_6=Document(
    page_content="Is the new iPhone worth the price? Read this review to find out.",
    metadata={"source":"website"},
)
document_7=Document(
    page_content="The top 10 soccer players in the world right now.",
    metadata={"source":"website"},
)
document_8=Document(
    page_content="LangGraph is the best framework for building stateful,agentic applications!",
    metadata={"source":"tweet"},
)
document_9=Document(
    page_content="The stock market is down 500 points today due to fears of a recession.",
    metadata={"source":"news"},
)
document_10=Document(
    page_content="I have a bad feeling I am going to get deleted:(",
    metadata={"source":"tweet"},
)
documents = [document_1, document_2, document_3, document_4, document_5, document_6, document_7, document_8, document_9, document_10]

#新增
# ids  = [str(i+1) for i in range(len(documents))]
#
# result = vector_store.add_documents(documents=documents, ids=ids)
# print(result)

#删除
result = vector_store.delete(ids=["1"])
print(result)
